﻿Imports System.Data.OleDb

Public Class ClsListBanco

    Dim conexao As String = "Provider=microsoft.ace.oledb.12.0;data source=DBSCP.accdb"
    Public objcon As New OleDb.OleDbConnection(conexao)


    Public Sub carregaListBox(ByVal lst As ListBox, ByVal query As String)

        ' lst.Items.Clear()


        ' abre a conexao

        objcon.Open()


        ' cria um comando select.

        Dim cmd As New OleDb.OleDbCommand(query, objcon)


        ' executa a consulta

        Dim db_reader As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.Default)


        ' exibe os resultados

        Dim texto As String

        Dim i As Integer

        Do While db_reader.Read

            texto = db_reader.Item(0).ToString

            For i = 1 To db_reader.FieldCount - 1

                texto &= vbTab & db_reader.Item(i).ToString

            Next i

            lst.Items.Add(texto)

        Loop


        ' fecha a conexao

        objcon.Close()

    End Sub

End Class
